package edu.rit.drh4818.raytracing.tone;

import java.awt.Color;
import java.awt.Point;

/**
 * @author Darren Headrick
 *
 */
public class Reinhard extends ToneReproduction
{
	private double a;
	private Point p;
	
	public Reinhard( double lmax, double ldmax )
	{
		super( lmax );
		this.a = .18;
	}
	
	public Reinhard( double lmax, double ldmax, double a )
	{
		super( lmax );
		this.a = a;
	}

	public Reinhard( double lmax, double ldmax, Point p )
	{
		super( lmax );
		this.p = p;
	}
	
	public Color[][] transform(Color[][] original) 
	{
		if( p != null ) a = calcLuminensce( original[p.x][p.y] );
		
		double sf = a / logAverage( original );
		
		Color[][] rv = new Color[ original.length ][ original[0].length ];
		
		for( int x = 0; x < original.length; x++ )
		{
			for( int y = 0; y < original[x].length; y++ )
			{
				double red = sf * calcLuminensce( original[x][y].getRed());
				red = (red / ( 1 + red ));
				double green = sf * calcLuminensce( original[x][y].getGreen());
				green = (green / (1 + green ));
				double blue = sf * calcLuminensce( original[x][y].getBlue());
				blue = (blue / ( 1 + blue ));
				rv[x][y] = new Color( (float)red, (float)green, (float)blue );
			}
		}
		
		return rv;
	}
}
